package com.jzoom.zoom.admin.controllers;

import com.jzoom.zoom.admin.models.DaoService;
import com.jzoom.zoom.common.annotations.Inject;
import com.jzoom.zoom.dao.Dao;
import com.jzoom.zoom.dao.driver.DbStructFactory;
import com.jzoom.zoom.dao.meta.TableMeta;
import com.jzoom.zoom.web.annotations.Controller;

import java.util.Collection;

/**
 * 数据库接口，对应DbStructFactory
 * 服务器之间的通信，使用的检查器是服务器之间的
 */
@Controller(key = "db")
public class DbStructApi{


    @Inject
    private DaoService daoService;


    public Collection<String> getTableNames(String ds) {
        Dao dao = daoService.getDao(ds);
        return  dao.getDbStructFactory().getTableNames(dao.ar());
    }

    public TableMeta getTableMeta(String ds, String tableName) {
        Dao dao = daoService.getDao(ds);
        return  dao.getDbStructFactory().getTableMeta(dao.ar(),tableName);
    }


    public Collection<DbStructFactory.TableNameAndComment> getNameAndComments(String ds) {
        Dao dao = daoService.getDao(ds);
        return  dao.getDbStructFactory().getNameAndComments(dao.ar());
    }

    public void clearCache(String ds) {
        Dao dao = daoService.getDao(ds);
        dao.clearCache();
    }
}
